/*
 * Poltrona.java
 *
 * Created on 5 de Outubro de 2007, 10:37
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package salas;

/**
 *
 * @author Juliano
 */
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

public class Poltrona extends JButton{
    
    private boolean ocupada;
    private boolean reservada;
    
    public Poltrona(){
        super();        
        initComponents();
    }
      
    public Poltrona(String text){
        super(text);
        initComponents();
    }
    
    public void initComponents(){
        this.setVisible(true);
        liberaPoltrona();
        this.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                alteraStatus(evt);
            }
        });
        this.setBackground(new Color(40,215,128));
        repaint();
    }

    public void alteraStatus(MouseEvent evt){
        if (evt.getButton() == 1){
            if (!ocupada){
               reservaPoltrona();
            }
            else{            
               JOptionPane.showMessageDialog(this,"Poltrona reservada","..:: OCUPADA ::..",JOptionPane.ERROR_MESSAGE);              
            }
        }
        else if (evt.getButton() == 3){      
            JOptionPane.showMessageDialog(this,"Poltrona liberada","..:: LIBERADA ::..",JOptionPane.INFORMATION_MESSAGE);
            liberaPoltrona();
        }
        repaint();
    }
    
    public void liberaPoltrona(){
         ocupada = false;
         this.setBackground(new Color(40,215,128));
         this.setIcon(new javax.swing.ImageIcon("/cartazes/poltrona.JPG"));
         this.setVerticalTextPosition(SwingConstants.TOP);
         this.setHorizontalTextPosition(SwingConstants.CENTER); 
        
         repaint();
    }
    
    public void reservaPoltrona(){
        ocupada = true;
       //this.setText(this.getText()+" - Reservada");
        this.setBackground(new Color(255,0,0));
        this.setIcon(new javax.swing.ImageIcon(path+"ocupada.jpg"));
        this.setVerticalTextPosition(SwingConstants.TOP);
        this.setHorizontalTextPosition(SwingConstants.CENTER); 
        
        repaint();
    }
    
    public boolean status(){
        return ocupada;
    }
    
    public boolean reservada(){
        return reservada;
    }
    
    public void reserva(){
        reservada = true;
    }
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
    }
    public  String path = "/cartazes/";
}
